#pragma once

#include "stdafx.h"
#include "LoggedEvent.h"

class CIrcConnection : public QThread
{
	Q_OBJECT;
private:
	volatile bool m_running;
	QQueue<QString> m_pendingCommands;
	QMutex m_pendingCommandsLock;
	QWaitCondition m_messagesPending;

	QTcpSocket* m_socket;

	void HandleIncomingCommand(QString command);
	void EstablishConnection();
protected:
	virtual QHostAddress GetHost() const = 0;
	virtual unsigned short GetPort() const = 0;
	virtual QString GetChannel() const = 0;
	virtual QString GetUser() const = 0;

signals:
	void LogEvent(CLoggedEvent* event);
	void ConnectionEstablished();
	

public slots:
	void CommandWaiting();
	void Disconnect();
	void ConnectionLost();
protected:
	void QueueCommand(QString command, bool highPriority = false);
	virtual void ProcessIncomingCommand(QString command) = 0;
public:
	CIrcConnection(void);
	virtual ~CIrcConnection(void);
	void run();
};
